chrome.extension.sendRequest({reqtype: 'options'}, function(response) {
	
	//Create Options Link
	if (response.options.optlink_main) {
		var optlink = $('#gbd5').find('ol').find('li:eq(0)').clone();
		optlink.find('a').text('Beautify G+');
		optlink.find('a').attr('href', '#');
		optlink.find('a').click( function() {
			window.open(chrome.extension.getURL('options.html'), '_blank');
		});		
		$('#gbd5').find('ol').find('li:eq(1)').after(optlink);
	}
	else {
	}
	
	//Fix Left Column
	if (response.options.leftColFixed) {
		if (response.options.chatFixed) {
			left_css = "";
			left_css += ".a-b-la-T {";
			left_css +=	"position:fixed !important;";
			left_css +=	"top: 0px !important;";
			left_css +=	"margin-top: 91px !important;";
			left_css +=	"width: 168px !important;";
			left_css += "}";
			left_css += ".a-b-g-dwPXm {";
			left_css +=	"margin-top: 80px !important;";
			left_css += "}";

			style = document.getElementsByTagName('head')[0].appendChild(document.createElement('style'));
			style.type = 'text/css';
			style.innerHTML = left_css;
		}
		else {
			var name = document.getElementsByClassName('a-b-Rf-A')[0].clientHeight;
			var menu = document.getElementsByClassName('a-b-la-A')[0].clientHeight;
			menupos = name + 92;
	
			left_css = "";
			left_css += ".a-b-Rf-A {";
			left_css +=	"background:#FFFFFF !important;";
			left_css +=	"z-index:0;";
			left_css +=	"position:fixed !important;";
			left_css +=	"top: 0px !important;";
			left_css +=	"margin-top: 92px !important;";
			left_css +=	"width: 168px !important;";
			left_css += "}";
			left_css += ".a-b-la-A {";
			left_css +=	"background:#FFFFFF !important;";
			left_css +=	"z-index:0;";
			left_css +=	"position:fixed !important;";
			left_css +=	"top: 0px !important;";
			left_css +=	"margin-top: ";
			left_css +=	menupos;
			left_css +=	"px !important;";
			left_css +=	"width: 168px !important;";
			left_css += "}";
			left_css += ".a-b-g-dwPXm {";
			left_css +=	"margin-top: 80px !important;";
			left_css += "}";
			
			style = document.getElementsByTagName('head')[0].appendChild(document.createElement('style'));
			style.type = 'text/css';
			style.innerHTML = left_css;
			
			var totalhight = name + menu + 91;
			$('div.a-b-la-mc-jO').css('margin-top',totalhight);
			$('div.a-b-la-mc-jO').css('z-index','-1');
		}
	}
	else {
	}
	
	//Fix Right Column
	if (response.options.rightColFixed) {
		right_css = "";
		right_css += ".a-Cs-T {";
		right_css += "	position:fixed !important;";
		right_css += "	top: 0px !important;";
		right_css += "	margin-top: 91px !important;";
		right_css += "	width: 195px !important;";
		right_css += "}";
		style = document.getElementsByTagName('head')[0].appendChild(document.createElement('style'));
		style.type = 'text/css';
		style.innerHTML = right_css;
	}
	else {
	}
	
	//Fix Navigation Bar
	if (response.options.navBarFixed) {
		nav_css = "";
		nav_css += ".a-Eo-T {";
		nav_css += "	left: 0px !important;";
		nav_css += "	position: fixed !important;";
		nav_css += "	top: 0px !important;";
		nav_css += "	width: 100% !important;";
		nav_css += "}";
		nav_css += ".a-U-T, .Sa-E-U-T {";
		nav_css += "	margin-top: 30px !important;";
		nav_css += "	left: 0px !important;";
		nav_css += "	position: fixed !important;";
		nav_css += "	top: 0px !important;";
		nav_css += "	width: 100% !important;";
		nav_css += "	z-index:1 !important;";
		nav_css += "	border-bottom:1px solid #D2D2D2"
		nav_css += "}";
		nav_css += "#content {";
		nav_css += "	margin-top:91px !important;";
		nav_css += "	z-index:0 !important;";
		nav_css += "}";
		nav_css += ".Sa-E-ec, .a-b-E-p-T, .Sa-E-p-T {";
		nav_css += "	padding-top: 98px !important;";
		nav_css += "}";
		style = document.getElementsByTagName('head')[0].appendChild(document.createElement('style'));
		style.type = 'text/css';
		style.innerHTML = nav_css;
	}
	else {
	}
	
	// Fixed Input Area
	if (response.options.userInputFixed) {
		input_css = "";
		input_css += ".inputwrap {";
		input_css += "	position:fixed !important;";
		input_css += "	top: 0px !important;";
		input_css += "	background: #FFFFFF !important;";
		input_css += "	z-index:2 !important;";
		input_css += "	margin-top: 91px !important;";
		input_css += "	padding-bottom: 20px !important;";
		input_css += "	border-bottom: 1px solid #EBEBEB;";
		input_css += "}";
		input_css += ".a-b-f-i-oa {";
		input_css += "	margin-top: 80px;";
		input_css += "}";
		input_css += ".a-c-sc-za-dc-m {";
		input_css += "	margin-top: -70px;";
		input_css += "}";
		style = document.getElementsByTagName('head')[0].appendChild(document.createElement('style'));
		style.type = 'text/css';
		style.innerHTML = input_css;
		function wrap () {
			$('.a-f-U, .a-b-n-A').wrapAll('<div class="inputwrap">');
		}
		function checkforinput () {
			if(document.getElementsByClassName('inputwrap')[0]){
			}
			else {
				wrap();
			}
		setTimeout(checkforinput, 1000);
		}
		checkforinput();
	}
	
	//Hide Suggestions
	if (response.options.hideSuggestions) {
		suggest_css = "";
		suggest_css += ".a-b-j-lc-Rd-A {";
		suggest_css += "	visibility:hidden;";
		suggest_css += "	display:none;";
		suggest_css += "}";
		style = document.getElementsByTagName('head')[0].appendChild(document.createElement('style'));
		style.type = 'text/css';
		style.innerHTML = suggest_css;
	}
	else {
	}
	
	//Hide Mobile Add
	if (response.options.hideMobile) {
		
		function hidemobile () {
			if($(".a-b-Cs-T")){
				$(".a-St-FK-L506cc").parent().remove();
			}
			else {
				setTimeout(hidemobile, 2000);
			}
		}
		hidemobile();
		
		$(".a-b-Cs-T").watch('display', function(){
			$(".a-St-FK-L506cc").parent().remove();
		});
	}	
	else {
	}
	
	// Audio Alerts
	if (response.options.audioalert) {
		sound = response.options.audiosound;
		remider = response.options.audioreminder;
		timer = response.options.audiotimer;
		i = '<audio id="notificationaudio" src="http://beautify.it/gplus/'+sound+'.ogg" style="display:none; visibility:hidden;"></audio>';
		var d = $('#gbg');
		d.append(i);
		function audiocheck() {
			if (document.getElementById('gbi1').innerHTML != "0"){
				if (response.options.audioreminder){
					audio = document.getElementById('notificationaudio');
					audio.play();
					setTimeout(audiocheck, timer);
				}
				else {
					audio = document.getElementById('notificationaudio');
					audio.play();
				}
			}
			else {
				setTimeout(audiocheck, 10000);
			}
		}
		setTimeout(audiocheck, 15000);
	}
	
	// Favicon Alerts
	if (response.options.faviconalert) {
		var head = document.getElementsByTagName('head')[0];
		var links = head.getElementsByTagName('link');
		for (var i in links) {
			if (links[i].rel == 'shortcut icon') {
				links[i].type = 'image/png';
				var shortcutLink = links[i];
			}
		}
		function updateFavicon() {
			if (document.getElementById('gbi1').innerHTML != "0") {
				count = document.getElementById('gbi1').innerHTML;
				var canvas = document.createElement('canvas');
				canvas.height = '16';
				canvas.width = '16';
			if (canvas.getContext) {
				var context = canvas.getContext('2d');
				context.font = 'bold 9px Sans-Serif';
				context.textBaseline = 'middle';
				var base = new Image();
				base.addEventListener('load', function() {
					context.drawImage(base, 0, 0);
					if (count > 0 && count < 10) {
						context.fillStyle = '#FFFFFF';
						context.fillText(count, 6, 9);
					} else if (count > 9 && count < 100) {
						context.fillStyle = '#FFFFFF';
						context.fillText(count, 4, 9);
					} else if (count > 99 && count < 1000) {
						context.fillStyle = '#FFFFFF';
						context.fillText('++', 3, 9);
					} else {
						context.fillStyle = '#FFFFFF';
						context.fillText('+++', 1, 9);
					}
					shortcutLink.href = canvas.toDataURL();
				});
				base.src = '';
			}
			} else {
				shortcutLink.type = 'image/x-icon';
				shortcutLink.href = 'https://ssl.gstatic.com/s2/oz/images/favicon.ico';
			}
			var frame = document.createElement('iframe');
			frame.display = 'none';
			frame.src = shortcutLink.href;
			document.body.appendChild(frame);
			document.body.removeChild(frame);
			setTimeout(updateFavicon, 5000);
		}
		updateFavicon();
	}
});